PATH![]() |
![]() ![]() |
On occasion you may want to use timers in your preemptive tasks. For example, say you want a task to send a message to a given queue every 20 milliseconds. To do so, you can set a timer to block your task for 20ms after sending the notification by calling the function MPDelayUntil .
Note
Note that in some cases you may want to use notification mechanisms to accomplish periodic actions, as described in Handling Periodic Actions .
In addition, you can create timers that will signal a specified notification mechanism after the timer expires. For example, say you have a task that is prompting the user to enter a name and password. Once you bring up the input dialog box, you may have another task (or the application) create a timer object to expire after five minutes. If the user has not entered a password during those five minutes, the timer expires and sends a message to the task, signaling that it should terminate.
You create a timer using the function MPCreateTimer and arm it by calling the function MPArmTimer . To specify the notification mechanisms to signal when the timer expires, you call the function MPSetTimerNotify . Note that you can signal one notification mechanism of each type if desired. For example, the timer can send a message to a queue and also set a bit in an event group when it expires.
The timers in Multiprocessing Services use time units of type AbsoluteTime , which increases monotonically since the host computer was started up. You can obtain the time since startup by calling the function UpTime . Multiprocessing Services also provides the functions DurationToAbsolute and AbsoluteToDuration which let you convert time between units of AbsoluteTime and units of type Duration . Note that you should not make any assumptions about what the AbsoluteTime units are based upon.